import React from "react";
import classNames from "classnames";
/**
 * ~~~js
 * 默认二封增强树组件
 * ~~~~
 */
export default function DevTreeDefaultHoc(WrappedComponent) {
    // 泛型限定
    return class extends WrappedComponent {
        parent = super.render();
        dataSource;
        defaultConfig = {};
        treeRef;
        get treeInstance() {
            return this.treeRef.current.instance;
        }
        constructor(...props) {
            super(...props);
            this.treeRef = React.createRef();
        }
        componentDidMount() { }
        componentWillUnmount() {
            console.log("卸载事件");
            this.dataSource.dispose();
        }
        ContextMenu(e) {
            const { column, row, columnIndex, rowIndex } = e;
            const { dataField, dataType } = column;
            let propsMenus = [];
            if (this.props.ContextMenu) {
                propsMenus = this.props.ContextMenu(e);
            }
            const defaultMenu = [
                {
                    text: "全部展开",
                    onItemClick: () => {
                        this.sortAsc(dataField);
                    },
                },
                {
                    text: "全部收起",
                    onItemClick: () => {
                        this.sortDesc(dataField);
                    },
                },
            ];
            return [...defaultMenu, ...propsMenus];
        }
        render() {
            const klass = classNames("cpas-grid", "PaperDevSortableGrid");
            const { ...rest } = this.props;
            let props = {
                className: klass,
                ...this.defaultConfig,
                ...rest,
                ref: this.gridRef,
            };
            return React.cloneElement(this.parent, { ...props });
        }
    };
}
